package com.hdsx.restful.glzt.structure.crk.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.esri.arcgis.geometry.IGeometry;
import com.hdsx.ao.base.BaseOpearte;
import com.hdsx.restful.glzt.roadline.lxxx.bean.Znode;
import com.hdsx.restful.glzt.structure.crk.bean.Crk;
import com.hdsx.restful.glzt.structure.crk.mapper.CrkMapper;
import com.hdsx.restful.glzt.structure.crk.service.CrkServer;
import com.hdsx.restful.glzt.structure.ql.bean.IntValueName;
import com.hdsx.restful.glzt.structure.ql.bean.StatisticalResult;
import com.hdsx.restful.util.Dao;
/**
 * qlServer实现类
 *
 */
@Service
public class CrkServerImpl  extends BaseOpearte<Crk> implements CrkServer {

	public CrkServerImpl() {
		super("GIS_CRK");
	}

	@Resource(name="crkMapper")
	private CrkMapper mapper;

	@Override
	public Crk getById(String id) {
		return mapper.queryOne(id);
	}

	@Override
	public boolean addCrk(Crk crk) {
		return mapper.add(crk)>0;
	}

	@Override
	public boolean updateCrk(Crk crk) {
		return mapper.update(crk)>0;
	}

	@Override
	public boolean deleteById(String id) {
		return mapper.delete(id)>0;
	}

	@Override
	public int queryCrkCountByLxbm(String lxbm) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		return mapper.countByLxbm(parameter);
	}

	@Override
	public List<Crk> getListByLxbm(String lxbm, int begin, int end) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("begin", begin);
		parameter.put("end", end);
		return mapper.selectListByLxbm(parameter);
	}

	@Override
	public int queryCrkCountXzqhbm(String xzqhbm) {
		if(xzqhbm!=null){
			if(xzqhbm.endsWith("0000")){
				xzqhbm=xzqhbm.substring(0,2);
			}else if(xzqhbm.endsWith("00")){
				xzqhbm=xzqhbm.substring(0,4);
			}
		}
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("xzqhbm", xzqhbm);
		return mapper.countByXzqhbm(parameter);
	}

	@Override
	public List<Crk> getListByXzqhbm(String xzqhbm, int begin, int end) {
		if(xzqhbm!=null){
			if(xzqhbm.endsWith("0000")){
				xzqhbm=xzqhbm.substring(0,2);
			}else if(xzqhbm.endsWith("00")){
				xzqhbm=xzqhbm.substring(0,4);
			}
		}
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("begin", begin);
		parameter.put("end", end);
		return mapper.selectListByXzqhbm(parameter);
	}

	@Override
	public int queryCount(String lxbm,String xzqhbm,String sxxfx,Double qdzh,Double zdzh,String name) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("sxxfx", sxxfx);
		parameter.put("qdzh", qdzh);
		parameter.put("zdzh", zdzh);
		parameter.put("name", name);
		return mapper.selectCount(parameter);
	}
	@Override
	public List<Crk> queryList(String lxbm,String xzqhbm,String sxxfx,Double qdzh,Double zdzh,String name,int begin, int end) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("sxxfx", sxxfx);
		parameter.put("qdzh", qdzh);
		parameter.put("zdzh", zdzh);
		parameter.put("name", name);
		parameter.put("begin", begin);
		parameter.put("end", end);
		List<Crk> lists=mapper.selectList(parameter);
		return lists;
	}

	@Override
	public Crk getOne(String crkbm) {
		return mapper.queryOne(crkbm);
	}
	
	@Override
	public List<Dao> getShapeById(String id) {
		Crk crk = mapper.getShapeById(id);
		IGeometry shape=selectShape("ID='"+id+"'");
		crk.setShape(shape);
		List<Dao> lists=new ArrayList<Dao>();
		lists.add(new Dao("出入口名称",crk.getCrkmc(),crk.getPtx(),crk.getPty()));
		lists.add(new Dao("出入口编码",crk.getCrkbm()));
		lists.add(new Dao("所在路线",crk.getLxbm()));
		lists.add(new Dao("中心桩号",crk.getZh()));
		lists.add(new Dao("出入口类型",crk.getLx()));
		return lists;
	}
	@Override
	public StatisticalResult countByParameter(Map<String,Object> map) {
		List<IntValueName> seriesData = mapper.countTotalByParameter(map);
		List<String> legendData = mapper.selectClassify(map);
		StatisticalResult sr = new StatisticalResult();
		sr.setChartsText("出入口统计");
		sr.setSeriesData(seriesData);
		sr.setLegendData(legendData);
		return sr;
	}
	@Override
   	public List<Znode> crkNode() {
   		List<Znode> Node = mapper.node();
   		return Node;
   	}
	
	 @Override
	 public int countTotal(Map<String, Object> map){
		 return mapper.countTotal(map);
	 }
	 @Override
	 public List<Crk> listAll(String lxbm,String xzqhbm,String sxxfx,Double qdzh,
			Double zdzh,String name) {
		return mapper.listAll(lxbm,xzqhbm,sxxfx,qdzh,zdzh,name);
	 }
	 @Override
	public Crk queryById(String id) {
			return mapper.selectById(id);
	}
	/**
	 * 分类细节
	 */
	@Override
	public List<Crk> detail(Map<String, Object> map){
		return mapper.detail(map);
	}
	@Override
	public int countDetail(Map<String, Object> map) {
		return  mapper.countDetail(map);
	}
	@Override
	public List<String> selectName(String name){
		return mapper.selectName(name);
	}
	 
}
